PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Scope of Subroutine Calls in Tell Statements

If you need to call a subroutine from within a Tell statement, you must use the reserved words of me or my to indicate that the subroutine is part of the script (not a command that should be sent to the object of the Tell statement).

For example, the minimumValue subroutine call in the following Tell statement is unsuccessful, even if the script contains the minimumValue routine defined in A Sample Subroutine, because AppleScript sends the minimumValue command to AppleWorks. If you run this script, you get an error message saying that AppleWorks does not understand the minimumValue message.

tell front document of application "AppleWorks"
    minimumValue(12, 400)
    copy result as string to word 10 of text body
end tell
--result: An error, because AppleWorks doesn't
--          understand the minimumValue message.

If you use the words of me in the subroutine call, as shown in the following Tell statement, the subroutine call is successful, because AppleScript knows that the subroutine is part of the script.

tell front document of application "AppleWorks"
    minimumValue(12, 400) of me
    copy result as string to word 10 of text body
end tell
--result: The subroutine call is successful.

You can use the word my before the subroutine call as a synonym for the words of me after the subroutine call. For example, the following two subroutine calls are equivalent:

minimumValue(12, 400) of me
my minimumValue(12, 400)

© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)